<template>
  <div class="fly-upload">
    <van-uploader 
        :after-read="afterRead"
        class="img-uploader"
        :max-count="1" 
        v-model="fileList"
        @delete="deleteFile"
      />
  </div>
</template>
<script>
export default {
  name: "FlyUpload",
  props:{
    list: {
      type: Array,
    },
    url: {
      type: String
    }
  },
  data() {
    return {
      fileList: [],
      imgKey:[]
    };
  },
  created() {
    this.fileList = this.list;
  },
  computed: {},
  methods: {
    afterRead(file) {
      // 此时可以自行将文件上传至服务器
      let params = new FormData();
      params.append("fileType", 'file');
      params.append("file", this.fileList[0].file);
      this.$http('post', '/common/upload', params, (data, msg) => {
        this.fileList = [{url: data.data.url}];
        this.$emit('update:url', data.data.url);
        
      })
    },
    deleteFile(data){
      this.fileList = [];
      this.$emit('update:url', '');
    }
  },
};
</script>

